package view.pieces;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.Rectangle2D;
import java.util.Observable;

import javax.swing.ImageIcon;

import resources.GlobalSettings;
import resources.ImageBundle;

import model.pieces.Target;

public class TargetDisplayView extends PieceDisplayView {

	private static final Image targetImage = new ImageIcon(
			ImageBundle.get("target_" + GlobalSettings.pieceImageWidth))
			.getImage();

	public TargetDisplayView(Graphics2D g2d, Target target) {
		super(g2d, target);
	}

	@Override
	public void paint(Graphics2D g2D) {
		this.g2D = g2D;

		if (((Target) piece).isFree()) {
			Rectangle2D rect = getPieceRectangle();

			this.g2D.setColor(GlobalSettings.levelPanelColor);
			this.g2D.fill(rect);
			this.g2D.setColor(GlobalSettings.levelPanelColor);
			this.g2D.draw(rect);

			this.g2D.drawImage(targetImage, (int) rect.getMinX(),
					(int) rect.getMinY(), (int) rect.getMaxX(),
					(int) rect.getMaxY(), 0, 0, GlobalSettings.pieceImageWidth,
					GlobalSettings.pieceImageHeight, null);
			/*
			 * this.g2D.setColor(Color.BLACK); this.g2D.fill3DRect((int)
			 * rect.getCenterX() - 5, (int) rect.getCenterY() - 5, 10, 10,
			 * true); this.g2D.setColor(Color.BLACK); this.g2D.draw3DRect((int)
			 * rect.getCenterX() - 5, (int) rect.getCenterY() - 5, 10, 10,
			 * true);
			 * 
			 * // this.g2D.setColor(Color.red); //
			 * this.g2D.drawLine((int)rect.getX
			 * (),(int)rect.getY(),(int)rect.getX
			 * ()+(int)rect.getWidth(),(int)rect.getY()+(int)rect.getHeight());
			 */
		}
	}

	@Override
	public void update(Observable o, Object arg) {
		this.paint(this.g2D);
	}

}
